from django.conf import settings
from django.core.mail import send_mail

from celery_tasks.celery import app
from meiduo_mall.libs.yuntongxun.sms import CCP


@app.task(bind=True)
def send_verify_email(self, verify_url, email):
    # 测试耗时
    import time
    time.sleep(10)

    result = -1

    # 1, 发送短信
    try:
        result = send_mail(
            subject='美多商城验证链接',
            message='点击链接激活邮箱:' + verify_url,
            recipient_list=[email],
            from_email=settings.EMAIL_FROM,
            html_message='点击链接激活邮箱:' + verify_url,
        )
        print('发送成功')
    except Exception as e:
        result = -1

    if result == -1:
        self.retry(exc=Exception('邮件发送失败'), countdown=5, max_retries=5)